extends IUsableComponent


class_name EffectComponent
"""
挂载效果
"""


enum UseMode {
    ## 添加
    Take,
    ## 删除
    Drop,
    ## 替换Replace
    Replace,
}

## 使用方式
@export var mode: UseMode = UseMode.Take
## 是否进行恢复
@export var is_resetable: bool = true
## 需要附加的效果
@export var effects: Array[EffectValue] = []


var __store_processor: EventCenter = null


## 应用效果
func apply(character: CharacterComponent) -> bool:
    if not super.apply(character):
        return false
    match mode:
        UseMode.Take:
            for e in effects:
                __mount_character.processor.take(e)
        UseMode.Drop:
            for e in effects:
                __mount_character.processor.drop(e)
        UseMode.Replace:
            if is_resetable:
                __store_processor = character.processor
            __mount_character.processor = EventCenter.new()
            for e in effects:
                __mount_character.take(e)
    return true

## 取消效果
func cancel() -> void:
    if is_resetable:
        match mode:
            UseMode.Take:
                for e in effects:
                    __mount_character.processor.drop(e)
            UseMode.Drop:
                for e in effects:
                    __mount_character.processor.take(e)
            UseMode.Replace:
                __mount_character.processor = __store_processor
                __store_processor = null
    super.cancel()
